<?php

namespace app\http\shop\controller;

use app\repository\dao\shop\BrandDao;
use support\Redis;
use support\Request;
use support\Response;

/**
 * @desc    品牌管理
 * @author  OverMiracle
 * @date    2024-02-19
 */
class Brand
{
    public function index(Request $request): Response
    {
        $data = [
            'page'  => $request->get('page', 1),
            'limit' => $request->get('limit', 20),
        ];
        $key = 'brand@' . md5(json_encode($data, 256));
        /** @var Redis $redis */
        $redis = Redis::connection('shop');
        $result = json_decode($redis->get($key) ?? '', true);
        if ($result == null) {
            $result = BrandDao::getList($data);
            $redis->set($key, json_encode($result, 256), null, 1800);
        }
        return json([
            'status'  => 200,
            'message' => 'success',
            'data'    => $result,
        ]);
    }
}